home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-26 | 2.0 KB | 82 lines | [TEXT/CWIE] |
-
- // mail <chelly@eden.com> or surf http://www.eden.com/~chelly for feedback
- // free source code - do whatever you like with it
-
- // loader for graphic elements that uses either mac or universal pictures
-
- #include "UnivPictLoader.h"
-
- #include "common.h"
- #include "gepicture.h"
-
- // Graphic Elements
- #include "gelemnts.h"
- #include "Rects.h"
-
- GE_CALLBACK( Boolean, LoadUnivPictElement)( GEWorldPtr world, GrafElPtr element,
- short startResNum, short nResources )
- {
- Boolean ok = true;
- GWorldPtr gWorld = nil;
- PixMapHandle pixH = nil;
- short err = 0;
-
- {
- element->resID = startResNum;
-
- // if element is already loaded, use its offscreen
- for ( GrafElPtr testElem = world->idList; testElem; testElem = testElem->nextByID )
- if ( testElem->resID == startResNum )
- {
- element->graphWorld = testElem->graphWorld;
- element->graphRect = testElem->graphRect;
- return true;
- }
-
- // get image size
- GEPicture* const pic = GetGEPicture( startResNum );
- if ( !pic ) goto abort;
- Rect box = GetGEPictureFrame( pic );
- DisposeGEPicture( pic );
-
- // set up element
- element->graphRect = box;
- Rect totalBox = box;
- totalBox.bottom *= nResources; // multi-frame element support
-
- // draw image(s) to offscreen
- err = NewGWorld( &gWorld, offscrnDepth, &totalBox, world->worldCTable, 0, 0 );
- if ( err ) goto abort;
- pixH = GetGWorldPixMap( gWorld );
- if ( !pixH ) goto abort;
- if ( !LockPixels( pixH ) ) goto abort;
- NoPurgePixels( pixH );
- CGrafPtr save_port;
- GDHandle save_dev;
- GetGWorld( &save_port, &save_dev );
- SetGWorld( gWorld, nil );
-
- for ( int counter = 0; counter < nResources; ++counter )
- {
- GEPicture* const pic = GetGEPicture( startResNum + counter );
- if ( pic )
- {
- DrawGEPicture( pic, &box );
- DisposeGEPicture( pic );
- RectOffset( &box, 0, RectHeight(&box) );
- }
- }
- SetGWorld( save_port, save_dev );
-
- element->graphWorld = gWorld;
- goto done;
- }
-
- abort:
- if ( gWorld ) DisposeGWorld( gWorld );
- ok = false;
- done:
- return ok;
- }
-
-